package cn.shequren.communityPeople.home.ui.view;

import android.content.Context;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.TextView;

import com.jz.community.basecomm.utils.SHelper;

import me.majiajie.pagerbottomtabstrip.internal.RoundMessageView;
import me.majiajie.pagerbottomtabstrip.item.BaseTabItem;

public class DrawableTabItem extends BaseTabItem {

    private ImageView mIcon;
    private final TextView mTitle;
    private final RoundMessageView mMessages;

    //默认的图片路径
    private int mDefaultDrawable;
    //选中的图片路径
    private int mCheckedDrawable;

    private int mDefaultTextColor = 0x56000000;
    private int mCheckedTextColor = 0x56000000;
    Context context;

    public DrawableTabItem(@NonNull Context context) {
        this(context, null);
    }

    public DrawableTabItem(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DrawableTabItem(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        LayoutInflater.from(context).inflate(me.majiajie.pagerbottomtabstrip.R.layout.item_normal, this, true);

        mIcon = (ImageView) findViewById(me.majiajie.pagerbottomtabstrip.R.id.icon);
        mTitle = (TextView) findViewById(me.majiajie.pagerbottomtabstrip.R.id.title);
        mMessages = (RoundMessageView) findViewById(me.majiajie.pagerbottomtabstrip.R.id.messages);
    }

    /**
     * 方便初始化的方法（加载本地图片）
     *
     * @param drawableRes        默认状态的图标
     * @param checkedDrawableRes 选中状态的图标
     * @param title              标题
     */
    public void initialize(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes, String title) {
        mDefaultDrawable = drawableRes;
        mCheckedDrawable = checkedDrawableRes;
        mTitle.setText(title);
        mTitle.setTextSize(SHelper.dp2px(context, 10));
    }

    @Override
    public void setChecked(boolean checked) {
        //本地图片
        if (checked) {
            mIcon.setImageResource(mCheckedDrawable);
            mTitle.setTextColor(mCheckedTextColor);
        } else {
            mIcon.setImageResource(mDefaultDrawable);
            mTitle.setTextColor(mDefaultTextColor);
        }


    }

    @Override
    public void setMessageNumber(int number) {
        mMessages.setMessageNumber(number);

    }

    @Override
    public void setHasMessage(boolean hasMessage) {
        mMessages.setHasMessage(hasMessage);

    }

    @Override
    public String getTitle() {
        return mTitle.getText().toString();
    }

    public void setTextDefaultColor(@ColorInt int color) {
        mDefaultTextColor = color;
    }

    public void setTextCheckedColor(@ColorInt int color) {
        mCheckedTextColor = color;
    }
}
